package dgut.haitaobao.util.response;

import java.util.Objects;

import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;
public class HttpResponse<T> implements Serializable {
    private int code;
    private String message;
    private T data;

    private HttpResponse() {
    }

    public static <T> HttpResponse<T> success() {
        return (HttpResponse<T>) custom(HttpResponseCode.SUCCESS, (Object)null, (String)null);
    }

    public static <T> HttpResponse<T> success(T t) {
        return custom(HttpResponseCode.SUCCESS, t, (String)null);
    }

    public static <T> HttpResponse<T> success(T t, String message) {
        return custom(HttpResponseCode.SUCCESS, t, message);
    }

    public static <T> HttpResponse<T> error() {
        return (HttpResponse<T>) custom(HttpResponseCode.ERROR, (Object)null, (String)null);
    }

    public static <T> HttpResponse<T> error(T t) {
        return custom(HttpResponseCode.ERROR, t, (String)null);
    }

    public static <T> HttpResponse<T> error(String message) {
        return (HttpResponse<T>) custom(HttpResponseCode.ERROR, (Object)null, message);
    }

    public static <T> HttpResponse<T> custom(HttpResponseCode wxHttpResponseCode) {
        return (HttpResponse<T>) custom(wxHttpResponseCode, (Object)null, (String)null);
    }

    public static <T> HttpResponse<T> custom(HttpResponseCode wxHttpResponseCode, String message) {
        return (HttpResponse<T>) custom(wxHttpResponseCode, (Object)null, message);
    }

    public static <T> HttpResponse<T> custom(HttpResponseCode wxHttpResponseCode, T t) {
        return custom(wxHttpResponseCode, t, (String)null);
    }

    public static <T> HttpResponse<T> custom(HttpResponseCode wxHttpResponseCode, T t, String message) {
        HttpResponse<T> response = new HttpResponse();
        response.setCode(wxHttpResponseCode.getCode());
        if (Objects.nonNull(t)) {
            response.setData(t);
        }

        if (StringUtils.isNotBlank(message)) {
            response.setMessage(message);
        } else {
            response.setMessage(wxHttpResponseCode.getMessage());
        }

        return response;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof HttpResponse)) {
            return false;
        } else {
            HttpResponse<?> other = (HttpResponse)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getCode() != other.getCode()) {
                return false;
            } else {
                Object this$message = this.getMessage();
                Object other$message = other.getMessage();
                if (this$message == null) {
                    if (other$message != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$message)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof HttpResponse;
    }

    @Override
    public int hashCode() {
        boolean PRIME = true;
        int result = 1;
        result = result * 59 + this.getCode();
        Object $message = this.getMessage();
        result = result * 59 + ($message == null ? 43 : $message.hashCode());
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return "HttpResponse(code=" + this.getCode() + ", message=" + this.getMessage() + ", data=" + this.getData() + ")";
    }
}
